Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
27 lines (21 loc) · 1.31 KB

3.5.4 - Coroutine/Http2/Client->send.md

File metadata and controls

27 lines (21 loc) · 1.31 KB

Coroutine\Http2\Client->send

向服务器发送请求,底层会自动建立一个Http2stream。可以同时发起多个请求。

function Coroutine\Http2\Client->send(swoole_http2_request $request) : int | false
  • 接受swoole_http2_request类的对象作为参数
  • 成功返回流的编号,编号为从1开始自增的奇数
  • 失败返回false

Request对象

swoole_http2_request对象没有任何方法,通过设置对象属性来写入请求相关的信息。

  • headers 数组,HTTP
  • method 字符串,设置请求方法,如GETPOST
  • path 字符串,设置URL路径,如/index.php?a=1&b=2,必须以/作为开始
  • cookies 数组,设置COOKIES
  • data 设置请求的body,如果为字符串时将直接作为RAW form-data进行发送
  • data 为数组时,底层自动会打包为x-www-form-urlencoded格式的POST内容,并设置Content-Typeapplication/x-www-form-urlencoded
  • pipeline 布尔型,如果设置为true,发送完$request后,不关闭stream,可以继续写入数据内容

PIPELINE

默认send方法在发送请求之后,会结束当前的Http2 Stream,启用PIPELINE后,底层会保持stream流,可以多次调用write方法,向服务器发送数据帧,请参考write方法。